package com.cxh.rmsq.utils.dialog

import android.content.Context
import android.graphics.Color
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.view.isVisible
import androidx.core.widget.NestedScrollView
import com.blankj.utilcode.util.TimeUtils
import com.cxh.rmsq.R
import com.hjq.shape.view.ShapeTextView
import com.lxj.xpopup.core.CenterPopupView
import com.lxj.xpopup.util.XPopupUtils
import kotlin.math.roundToInt


class ShoukuanAccountPopup(
    context: Context,
    type: Int,
    aliPay: String,
    wxPay: String,
    content: String,
    click: onClick
) :
    CenterPopupView(context) {

    interface onClick {
        fun click(s: Int, s1: String)
    }

    var func: onClick
    var aliPay: String
    var wxPay: String
    var content: String
    var type: Int
    var payType: Int = 2 //1微信2支付宝

    init {
        this.func = click
        this.aliPay = aliPay
        this.wxPay = wxPay
        this.content = content
        this.type = type
    }

    override fun getImplLayoutId(): Int {
        return R.layout.shoukuan_popup
    }

    override fun onCreate() {
        super.onCreate()

        var tv_content_child = findViewById<TextView>(R.id.tv_content_child)
        var iv_img = findViewById<ImageView>(R.id.iv_img)

        var ll_alipay = findViewById<LinearLayout>(R.id.ll_alipay)
        var iv_alipay = findViewById<ImageView>(R.id.iv_alipay)
        var tv_alipay = findViewById<TextView>(R.id.tv_alipay)
        var ll_wechat = findViewById<LinearLayout>(R.id.ll_wechat)
        var iv_wechat = findViewById<ImageView>(R.id.iv_wechat)
        var tv_wechat = findViewById<TextView>(R.id.tv_wechat)

        var tv_confirm = findViewById<TextView>(R.id.tv_confirm)

        tv_content_child.text = "您的" + content + "已收集成功"
        iv_img.setImageResource(R.mipmap.icon_clue_sucess)

        tv_alipay.text = "支付宝($aliPay)"
        tv_wechat.text = "微信($wxPay)"
        ll_alipay.setOnClickListener {
            payType = 2
            iv_alipay.setImageResource(R.mipmap.icon_account_sel)
            iv_wechat.setImageResource(R.mipmap.icon_account_unsel)
        }
        ll_wechat.setOnClickListener {
            payType = 1
            iv_wechat.setImageResource(R.mipmap.icon_account_sel)
            iv_alipay.setImageResource(R.mipmap.icon_account_unsel)
        }
        tv_confirm.setOnClickListener {
            func.click(
                payType,
                ""
            )
            dismiss()
        }
    }

    // 最大高度为Window的0.85
    override fun getMaxHeight(): Int {
        return ((XPopupUtils.getAppHeight(context) * .85f).roundToInt())
    }

}